<template>
    <reviewApprove ref="reviewApprove" />
    <batchVoidView ref="batchVoidView" />
    <reviewSummary ref="reviewSummary" />
    <div class="app-table">
        <div class="app-body">
            <div class="app-search">
                <el-form :inline="true" class="demo-form-inline" v-model="form">
                    <el-form-item label="姓名" style="width:200px">
                        <el-input placeholder="请输入姓名" v-model="form.name" @blur="blurInput"></el-input>
                    </el-form-item>
                    <el-form-item label="选科" prop="courseType" style="width:200px;">
                        <el-select v-model="form.courseType" autocomplete="off" placeholder="请选择选科"
                            @change="selectChange" clearable>
                            <el-option key="1" value="物化生" label="物化生"></el-option>
                            <el-option key="2" value="物化地" label="物化地"></el-option>
                            <el-option key="3" value="物化政" label="物化政"></el-option>
                            <!-- <el-option key="4" value="物生政" label="物生政"></el-option> -->
                        </el-select>
                    </el-form-item>
                    <el-form-item label="总分" style="width:200px; ">
                        <el-input placeholder="请输入总分" v-model="form.total" @input="totalInput"></el-input>
                    </el-form-item>
                    <el-form-item label="以上以下" style="width:240px;">
                        <el-select v-model="form.radio" autocomplete="off" placeholder="请选择分数以上以下" @change="changeTotal"
                            clearable>
                            <!-- @clear="clearableHandle" -->
                            <el-option :key="index" :value="item.id" :label="item.label"
                                v-for="(item, index) in rangeData"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="状态" prop="typeName" style="width:200px">
                        <el-cascader :options="options" placeholder="请选择审核状态" v-model="form.status"
                            @change="changeStatus" clearable />
                    </el-form-item>
                    <el-form-item>
                        <el-button class="serach_btn" type="primary" @click="onSubmit"
                            @keyup.enter="searchEnter">搜索</el-button>
                        <el-button class="export_btn" type="warning" @click="batchVoid">批量作废</el-button>
                        <el-button class="add_btn" type="warning" @click="downData">下载数据</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <el-table :data="list" style="width: 100%;">
                <el-table-column prop="id" label="序号" width="70" />
                <el-table-column prop="studentName" label="姓名" width="80" />
                <el-table-column prop="studentNumber" label="学号" width="100" />
                <el-table-column prop="sex" label="性别" width="60">
                    <template #default="scope">
                        <span v-if="scope.row.sex == 1">男</span>
                        <span v-if="scope.row.sex == 2">女</span>
                    </template>
                </el-table-column>
                <el-table-column prop="schoolName" label="毕业学校" width="200" />
                <el-table-column prop="courseType" label="选科组合" width="100" />
                <el-table-column prop="mobile1" label="联系电话" width="150" />
                <el-table-column prop="total" label="总分" width="70" />
                <!-- <el-table-column prop="studentNumber" label="学号" />
                <el-table-column prop="approvalTime" label="审批时间" width="200" /> -->
                <el-table-column prop="" label="审批状态" width="130">
                    <template style="display: block" #default="scope">
                        <p v-if="!scope.row.status || scope.row.status == 1">尚未审核</p>
                        <p v-if="scope.row.status == 2 && scope.row.payStatus == '01'">尚未缴费</p>
                        <p v-if="scope.row.status == 3 || (scope.row.status == 2 && scope.row.payStatus == '03')">已缴费
                        </p>
                        <p v-if="scope.row.status == 4">不符合录取标准</p>
                        <p v-if="scope.row.status == 5">个人信息错误</p>
                        <p v-if="scope.row.status == 6">审核过期</p>
                    </template>
                </el-table-column>
                <el-table-column prop="" label="是否退费" width="100">
                    <template style="display: block" #default="scope">
                        <p v-if="scope.row.isRefund > 0">是</p>
                        <p v-else>否</p>
                    </template>
                </el-table-column>
                <el-table-column prop="scoreStatus" label="状态信息" width="170">
                    <template style="display: block" #default="scope">
                        <p v-if="scope.row.scoreStatus == '考生信息不存在'" style="color: red;">身份证号或考生号有误</p>
                        <p v-if="scope.row.scoreStatus == '密码错误'" style="color: red;">密码错误</p>
                        <p v-if="scope.row.scoreStatus == '选科错误'" style="color: red;">选科错误</p>
                        <p v-if="scope.row.scoreStatus == '分数不准确'" style="color: red;">分数不准确</p>
                        <p v-if="scope.row.scoreStatus == '分数正确' || scope.row.scoreStatus == 1">分数正确</p>
                        <p v-if="!scope.row.scoreStatus">审核中</p>
                    </template>
                </el-table-column>

                <el-table-column label="操作" width="200px">
                    <template style="display: block" #default="scope">
                        <!-- v-if="score.row.status == 1" -->
                        <el-button class="edit_btn" size="small" type="primary" @click="getStudentInfo(scope.row.id)">审批
                        </el-button>
                        <!-- <el-button class="del_btn" size="small" type="danger"
                            @click="deleteTeacherSignInStatistics(scope.row.id)">删除
                        </el-button> -->
                        <el-button class="del_btn" size="small" type="danger" @click="aloneVoidHandle(scope.row)">作废
                        </el-button>
                    </template>
                </el-table-column>
                <el-table-column></el-table-column>
                <template v-slot:empty>
                    <el-empty description="暂无数据"></el-empty>
                </template>
            </el-table>
            <div style="margin-top: 10px">
                <el-config-provider :locale="locale">
                    <el-pagination :total="total" :page-size="pageSize" :current-page="page"
                        :page-sizes="[5, 10, 20, 30, 40, 50, 100]" layout="total, sizes, prev, pager, next, jumper"
                        @size-change="changePageSize" @current-change="changeCurrentPage">
                    </el-pagination>
                </el-config-provider>
            </div>
        </div>
        <bottomView></bottomView>
    </div>
    <a href="https://wx.zhengzhong.cn/upload/1721094663864.xls" download="复习生报名_2024-07-16.xlsx" ref="downloadLink"
        style="display: none;"></a>
</template>
<script>
import { ElConfigProvider, ElMessageBox, ElMessage } from "element-plus";
import zhCn from "element-plus/lib/locale/lang/zh-cn";
import { httpService } from "@/utils/httpService";
import { formatTime1, formatTime } from "@/utils/dateFormat";
import { Picture as IconPicture, Upload } from "@element-plus/icons-vue";
import bottomView from "@/components/bottom.vue";
import reviewApprove from "@/components/reviewStudent/reviewApprove.vue";
import batchVoidView from "@/components/reviewStudent/batchVoidView.vue";
import reviewSummary from "@/components/reviewStudent/reviewSummary.vue";
// import addEditPbArticleView from "@/components/reportWork/addEditPbArticle.vue";
export default {
    name: "ReviewStudentListView",
    data() {
        return {
            type: 0,
            title: "",
            page: 1,
            pageSize: 10,
            total: 0,
            limit: 10,
            list: [],
            name: "",
            changeData: [],
            payStatus: "",
            downloadUrl: "",
            downloadName: "",
            form: {
                name: "",
                typeName: "",
                courseType: "",
                total: 450,
                approvalTimeStr: "",
                status: 1,
                payStatus: "",
                radio: 2,
                startTotal: "450",
                endTotal: "1000",
            },
            options: [
                {
                    value: 1,
                    label: '尚未审核',
                    children: [],
                },
                {
                    value: 2,
                    label: '已审核',
                    children: [
                        {
                            value: '01',
                            label: '尚未缴费',
                            children: []
                        },
                        {
                            value: '03',
                            label: '已经缴费',
                            children: [],
                        },
                    ],
                },
                {
                    value: 4,
                    label: '不符合录取标准',
                    children: [],
                },
                {
                    value: 5,
                    label: '个人信息错误',
                    children: [],
                },
                {
                    value: 6,
                    label: '审批过期',
                    children: [],
                },
                {
                    value: 99,
                    label: '申请退费',
                },

            ],
            rangeData: [

                {
                    id: 1,
                    value: 450,
                    label: `450分以下`,
                    startTotal: 0,
                    endTotal: 450,
                },
                {
                    id: 2,
                    value: 450,
                    label: `450分及以上`,
                    startTotal: 450,
                    endTotal: 1000,
                },
            ]
        };
    },
    components: {
        IconPicture,
        ElConfigProvider,
        ElMessageBox,
        bottomView,
        ElMessage,
        reviewApprove,
        batchVoidView,
        reviewSummary,
    },
    setup() {
        return {
            locale: zhCn,
        };
    },
    mounted() {
        this.getReviewStudentList();
    },
    methods: {

        searchEnter: function (e) {
            // 使用 which 和 keyCode 属性来解决兼容问题
            var keyCode = window.event ? e.keyCode : e.which;
            var val = e.target.value;
            if (keyCode == 13 && val) {
                this.page = 1
                this.getReviewStudentList();
            }
        },
        changeTime(value) {
            this.form.approvalTimeStr = formatTime1(value)
        },
        focusTimeHandle() {
            this.form.approvalTimeStr = formatTime1(new Date())
        },
        selectChange(value) {
            this.getReviewStudentList();
        },
        blurInput(value) {
            this.getReviewStudentList();
        },



        changeTotal(value) {
            if (!value) {
                this.form.startTotal = ""
                this.form.endTotal = ""
                this.page = 1
                this.getReviewStudentList();
                return
            }
            if (this.form.total == 450 && this.form.radio == 1) {
                this.form.startTotal = 0
                this.form.endTotal = 450
            } else if (this.form.total == 450 && this.form.radio == 2) {
                this.form.startTotal = 450
                this.form.endTotal = 1000
            } else {
                const obj = this.rangeData.filter(item => item.id == value)[0]
                if (obj.id == 1) {
                    this.form.startTotal = 0
                    this.form.endTotal = obj.endTotal
                } else {
                    this.form.startTotal = obj.startTotal
                    this.form.endTotal = 1000
                }
            }
            this.page = 1
            this.getReviewStudentList();
        },
        changeStatus(value) {
            this.changeData = value
            this.page = 1
            this.getReviewStudentList();

        },
        totalInput(value) {
            if (value == "") {
                this.form.startTotal = ""
                this.form.endTotal = ""
                this.form.radio = ""
                return
            }
            this.form.radio = ""
            this.rangeData = [
                {
                    id: 1,
                    value: value,
                    label: `${value}分以下`,
                    startTotal: 0,
                    endTotal: Number(value),
                },
                {
                    id: 2,
                    value: value,
                    label: `${value}分及以上`,
                    startTotal: Number(value),
                    endTotal: 1000,
                },
            ]
        },

        batchVoid() {
            this.$refs.batchVoidView.title = "批量作废"
            this.$refs.batchVoidView.dialogFormVisible = true

        },
        getStudentInfo(id) {
            this.$refs.reviewApprove.dialogFormVisible = true;
            this.$refs.reviewApprove.getQueryById(id)
            // this.$refs.reviewApprove.getClassList() 
        },
        deleteTeacherSignInStatistics(id) {
            ElMessageBox.confirm("确定要删除本条记录吗？", "提醒", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    httpService("/javaApi/reviewStudentForm/deleteById", "id=" + id, "post").then(
                        (data) => {
                            if (data.code == 200) {
                                ElMessage.success("删除成功");
                                this.getReviewStudentList();
                            } else {
                                ElMessage.error("删除失败，请重试！");
                            }
                        }
                    );
                })
                .catch(() => {
                });
        },
        aloneVoidHandle(data) {
            const date = formatTime1(new Date())
            console.log(date);
            ElMessageBox.confirm(`确定要作废${data.studentName}的报名信息吗？`, "提醒", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    let params = new FormData()
                    params.append("id", data.id)
                    params.append("approvalTimeStr", date)
                    httpService("/javaApi/reviewStudentForm/repeal ", params, "post").then(
                        (data) => {
                            if (data.code == 200) {
                                ElMessage.success("作废成功");
                                this.getReviewStudentList();
                            } else {
                                ElMessage.error("作废失败，请重试！");
                            }
                        }
                    );
                })
                .catch(() => {
                });
        },
        reloadData() {
            this.page = 1;
            this.getReviewStudentList()
        },
        exportExcel(data, fileName) {
            let link = document.createElement('a'), fileUrl = window.URL.createObjectURL(new Blob([data]));
            link.style.display = 'none';
            link.href = fileUrl;
            link.setAttribute('download', fileName + '.xlsx');
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
            window.URL.revokeObjectURL(fileUrl)
        },
        onSubmit() {
            this.getReviewStudentList();
        },
        // 每页记录数改变，size：回调参数，表示当前选中的“每页条数”
        changePageSize(size) {
            this.pageSize = size;
            this.limit = size;
            this.getReviewStudentList();
        },

        // 改变页码，page：回调参数，表示当前选中的“页码”
        changeCurrentPage(page) {
            this.page = page;
            this.getReviewStudentList();
        },
        getReviewStudentList() {
            let startTotal = ''
            let endTotal = ''
            if (this.form.radio) {
                if (this.form.radio.flag == 'startTotal') {
                    startTotal = this.form.radio.value
                } else {
                    endTotal = this.form.radio.value
                }
            }

            let myStatus = '1'
            let myPayStatus = ''
            let isRefund = ''
            if (!this.changeData) {
                myStatus = ""
            } else if (this.changeData.length == 1) {
                if (this.changeData[0] == 99) {
                    isRefund = 0
                    myStatus = ''
                    myPayStatus = ''
                } else {
                    myStatus = this.changeData[0]
                }
            } else if (this.changeData.length == 2) {
                this.changeData[1] == "01" ? myStatus = 2 : myStatus = ""
                myPayStatus = this.changeData[1]
            }

            httpService(
                "/javaApi/reviewStudentForm/list/" + this.page + "/" + this.pageSize,
                {
                    studentName: this.form.name,
                    courseType: this.form.courseType ? this.form.courseType : "",
                    status: myStatus,
                    payStatus: myPayStatus,
                    startTotal: this.form.startTotal,
                    endTotal: this.form.endTotal,
                    isRefund: isRefund,
                },
                "get"
            ).then((data) => {
                if (data.list) {
                    data.list.map(item => {
                        if (item.approvalTime) {
                            item.approvalTime = formatTime1(item.approvalTime)
                        }
                        if (item.mobile1) {
                            item.mobile1 = item.mobile1.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
                        }
                    })
                }
                this.list = data.list;
                this.total = data.total;
                this.pageCount = data.pages;
            });
        },
        downData() {
            let startTotal = ''
            let endTotal = ''
            if (this.form.radio) {
                if (this.form.radio.flag == 'startTotal') {
                    startTotal = this.form.radio.value
                } else {
                    endTotal = this.form.radio.value
                }
            }

            let myStatus = '1'
            let myPayStatus = ''
            let isRefund = ''
            if (!this.changeData) {
                myStatus = ""
            } else if (this.changeData.length == 1) {
                if (this.changeData[0] == 99) {
                    isRefund = 0
                    myStatus = ''
                    myPayStatus = ''
                } else {
                    myStatus = this.changeData[0]
                }
            } else if (this.changeData.length == 2) {
                myStatus = this.changeData[0]
                myPayStatus = this.changeData[1]
            }
            httpService(
                "/javaApi/reviewStudentForm/exportExcel",
                {
                    studentName: this.form.name,
                    courseType: this.form.courseType ? this.form.courseType : "",
                    status: myStatus,
                    payStatus: myPayStatus,
                    startTotal: this.form.startTotal,
                    endTotal: this.form.endTotal,
                    isRefund: isRefund,
                },
                "get"
            ).then((data) => {
                const nowTime = formatTime(new Date())
                if (data.code == 200) {
                    window.open("https://wx.zhengzhong.cn/" + data.message, '_blank')
                } else {
                    ElMessage.error("下载失败，请重试！");
                }
            });

        },

    },
};
</script>
<style scoped>
.app-table {
    background: #eff3f5;
    padding: 5px 10px 10px;
}

.app-search {}


.app-body {
    background: white;
    width: calc(100% - 40px);
    padding: 20px 20px 10px 20px;
    margin-bottom: 10px;
    min-height: calc(100vh - 238px);
}

.serach_btn {
    background-color: #007EFF;
    color: #fff;
    border-radius: 8px;
    border: none;
}

.add_btn {
    background-color: #00c78c;
    color: #fff;
    border-radius: 8px;
    border: none;
}

.export_btn {
    background-color: #FF7200;
    border-radius: 8px;
    color: #fff;
    border: none;
}

.export_btn1 {
    background-color: #FFF;
    border: 1px solid #007EFF;
    color: #007EFF;
    border-radius: 8px;
    box-sizing: border-box;
}

.edit_btn {
    background-color: #fff;
    color: #007EFF;
    border: none;
}

.del_btn {
    background-color: #fff;
    color: #FF0000;
    border: none;
}

input {
    flex: 1;
    height: 30px;
    border: none;
    outline: none;
    font-size: 16px;
    text-align: start;
}

/* .el-table{
    width: 80%;
} */
</style>
